<template>
  <div class="content">
    <el-card>
      <el-form :model="form">
        <el-form-item label="账号">
          <el-input v-model="form.username" />
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.password" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="width: 100%" @click="onSubmit"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script setup>
import { reactive } from "vue";
import router from "../router/index";
const form = reactive({
  username: "zhifou",
  password: "123456",
});
// 登录
const onSubmit = () => {
  let menusOne = [
    {
      id: 69,
      parentId: null,
      name: "用户管理",
      type: 0,
      path: "/user",
      component: "",
      perms: "",
      children: [
        {
          id: 87,
          parentId: 69,
          name: "用户列表",
          type: 1,
          path: "list",
          component: "user/index",
          perms: "",
          children: null,
        },
      ],
    },
    {
      id: 78,
      parentId: null,
      name: "商品管理",
      type: 0,
      path: "/goods",
      component: "",
      perms: "",
      children: [
        {
          id: 78,
          parentId: 79,
          name: "商品列表",
          type: 1,
          path: "list",
          component: "goods/index",
          perms: "",
          children: null,
        },
      ],
    },
    {
      id: 88,
      parentId: null,
      name: "订单管理",
      type: 0,
      path: "/order",
      component: "",
      perms: "",
      children: [
        {
          id: 89,
          parentId: 88,
          name: "订单列表",
          type: 1,
          path: "list",
          component: "order/index",
          perms: "",
          children: null,
        },
      ],
    },
  ];
  let menusTwo = [
    {
      id: 69,
      parentId: null,
      name: "用户管理",
      type: 0,
      path: "/user",
      component: "",
      perms: "",
      children: [
        {
          id: 87,
          parentId: 69,
          name: "用户列表",
          type: 1,
          path: "list",
          component: "user/index",
          perms: "",
          children: null,
        },
      ],
    },
  ];
  // 模拟登录请求
  const res = {
    data: {
      code: 200,
      menuList: [],
      message: "请求成功",
    },
  };
  if (form.username === "admin") {
    res.data.menuList = menusOne;
  } else {
    res.data.menuList = menusTwo;
  }
  sessionStorage.setItem("menuList", JSON.stringify(res.data.menuList));
  sessionStorage.setItem(
    "userInfo",
    JSON.stringify({ username: form.username })
  );
  router.push("/home");
};
</script>
<style lang="scss" scoped>
.content {
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 15%;
}
</style>
